<template>
  <div class="app-container">
    <el-row :gutter="20">
      <el-col>
      <!--在线数据-->
      <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="80px" v-show="showSearch" >
        <el-form-item label="真实姓名" prop="realName">
          <el-input v-model="queryParams.realName" placeholder="请输入真实姓名" size="small" clearable style="width: 150px"/>
        </el-form-item>

        <el-form-item label="登录帐号" prop="loginName">
          <el-input v-model="queryParams.loginName" placeholder="请输入登录帐号" size="small" clearable style="width: 150px"/>
        </el-form-item>
        <el-form-item>
          <el-button type="primary"  size="mini" icon="el-icon-search" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery('queryForm')">重置</el-button>
        </el-form-item>
      </el-form>

      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button type="primary" v-hasPermi="['forceKickOutOnlineUser']"  icon="el-icon-switch-button" size="mini" :disabled="single" @click="forceKickOutOnlineUser">强制踢出</el-button>
        </el-col>

        <right-toolbar :showSearch.sync="showSearch" @queryTable="queryMonitorUserOnlinePageResList" :columns="columns"></right-toolbar>
      </el-row>

        <el-table ref="multipleTable" :stripe="true" v-loading="loading" :data="dataList" @selection-change="handleSelectionChange"
                  @sort-change='tableSortChange' :default-sort="{prop: 'sort', order: 'descending'}">
          <el-table-column type="selection" align="center"/>
          <el-table-column label="真实姓名" align="left" prop="realName"/>
          <el-table-column label="登录帐号" align="left" prop="loginName"/>
          <el-table-column label="用户类型" align="center" prop="userTypeName"/>
          <el-table-column label="登录IP" align="left" prop="loginIp"  width="200"/>
          <el-table-column label="登录时间" align="left" prop="loginTime" width="200" />
          <el-table-column label="操作" align="center" width="150" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-button size="mini" type="text" v-hasPermi="['forceKickOutOnlineUser']" icon="el-icon-switch-button"  @click="forceKickOutOnlineUser(scope.row)">强踢</el-button>
            </template>
          </el-table-column>
        </el-table>
        <pagination v-show="total>0" :total="total" :page.sync="queryParams.page" :limit.sync="queryParams.rows"
                    @pagination="queryMonitorUserOnlinePageResList"/>
      </el-col>
    </el-row>
  </div>
</template>
<script>
  import {queryMonitorUserOnlinePageResList, forceKickOutOnlineUserByOnlineId} from '@/api/monitor/monitorUserOnline'
  //默认查询参数
  let defaultQueryParams = {
    realName: undefined,
    loginName: undefined,
    page: 1,
    rows: 10
  }
  export default {
    name: "monitorUserOnlineAdmin",
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 总条数
        total: 0,
        // 显示搜索条件
        showSearch: true,
        // table表格数据
        dataList: [],
        // 查询参数
        queryParams: { ...defaultQueryParams },
        //列信息
        columns: []
      }
    },
    created() {
      this.queryMonitorUserOnlinePageResList();
    },
    methods: {
      /** 查询岗位列表 */
      queryMonitorUserOnlinePageResList() {
        this.loading = true
        queryMonitorUserOnlinePageResList(this.queryParams).then(response => {
          this.dataList = response.data.records
          this.total = response.data.total
          this.loading = false
        })
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.onlineId)
        this.single = selection.length !== 1;
        this.multiple = !selection.length
      },
      //排序
      tableSortChange(column){
        //格式化排序参数，构建中
        this.orderByFormat(this.queryParams,column);
        //执行查询方法
        this.queryMonitorUserOnlinePageResList()
      },
      /** 强制退出 */
      forceKickOutOnlineUser(row) {
        row = row.isTrusted ? this.$refs.multipleTable.selection[0] : row;
        this.$confirm('是否确认强制踢出会话?', "警告", {
          cancelButtonText: "取消",
          confirmButtonText: "确定",
          type: "warning"
        }).then(function() {
          const onlineId={onlineId:row.onlineId}
          return forceKickOutOnlineUserByOnlineId(onlineId);
        }).then(response => {
          this.$modal.msgSuccess(response.message)
          this.queryMonitorUserOnlinePageResList();
        }).catch(function() {});
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.page = 1
        this.queryMonitorUserOnlinePageResList()
      },
      /** 重置按钮操作 */
      resetQuery(fromId) {
        this.resetForm(fromId);
        this.handleQuery()
      }
    }
  }
</script>
